import { ts,  rule, DslRule } from "qvog-dsl";

import { assert, beforeAll, describe, test } from 'vitest';
import { CHECK_MODE, testCaseCheck } from '../../common/testCommon';
import { CheckEntry, Rule } from '../../../../../src/Index';
import path from 'path';

let realPath: string = '';
let checkEntry: CheckEntry;
let checkEntryF: CheckEntry;

beforeAll(async () => {
    let dslRule: DslRule = rule()
        .match((node): node is ts.VariableDeclaration => ts.isVariableDeclaration(node))
        .when((node): boolean => {
            return true;
        })
        .report({
            severity: 'SEVERITY',
            description: 'DESCRIPTION',
            docPath: 'DOC_PATH'
        });
    const mockRule: Rule = new Rule('');
    checkEntry = await testCaseCheck('./test/unittest/sample/ArrayTypeCheckDSL', mockRule, CHECK_MODE.FILE2CHECK, dslRule, false, true);
    realPath = checkEntry.scene.getRealProjectDir();

    let dslRuleF: DslRule = rule()
        .match((node): node is ts.VariableDeclaration => ts.isVariableDeclaration(node))
        .when((node): boolean => {
            return false;
        })
        .report({
            severity: 'SEVERITY',
            description: 'DESCRIPTION',
            docPath: 'DOC_PATH'
        });
    const mockRuleF: Rule = new Rule('');
    checkEntryF = await testCaseCheck('./test/unittest/sample/ArrayTypeCheckDSL', mockRuleF, CHECK_MODE.FILE2CHECK, dslRuleF, false, true);
})

describe('whenTest', () => {
    test('whenTest_001', () => {
        const detectFile: string = path.join(realPath, 'ArrayTypeCheckDSLReport.ts');
        const detectFileReport = checkEntry.fileChecks.find((fileCheck) => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.equal(detectFileReport?.issues.length, 2, 'The number of reported line is different from the expected number of line.');
    }),
    test('whenTest_002', () => {
        const detectFile: string = path.join(realPath, 'ArrayTypeCheckDSLReport.ts');
        const detectFileReport = checkEntryF.fileChecks.find((fileCheck) => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.equal(detectFileReport?.issues.length, 0, 'The number of reported line is different from the expected number of line.');
    })
})